//
//  XCBlueSendTool.swift
//  XCBlue
//
//  Created by mac on 2025/2/14.
//

import Foundation


class XCBlueSendTool {
    // 下发时间
    static func sendTimeToDevice() {
        let formatStringForHours = DateFormatter.dateFormat(fromTemplate: "j", options: 0, locale: Locale.current)
        let is12 = formatStringForHours?.contains("a") ?? false
        let offset = TimeZone.current.secondsFromGMT()

        let timeString = String(format: "P01,%@,%d,%d,%.1f", getDateWithFormatterString(formatter: "yyyyMMddHHmmssSSS"), is12 ? 1 : 0, 1, Double(offset) / 3600.0)
        print("发送数据：\(timeString)")
        if let data = timeString.data(using: .utf8) {
            XCBluetoothManager.shared.sendMessageToDevice(data: data)
        }
    }
    
    // 获取设备电量
    static func getDeviceElectricity() {
        
        let eleStr = String(format: "P02,%@",getDateWithFormatterString(formatter: "yyyyMMddHHmmssSSS"))
        print("发送数据：\(eleStr)")
        
        if let data = eleStr.data(using: .utf8) {
            XCBluetoothManager.shared.sendMessageToDevice(data: data)
        }
    }
}
